

//
//  VideoDetailView.m
//  Present
//
//  Created by dllo on 15/10/12.
//  Copyright (c) 2015年 Lemon. All rights reserved.
//

#import "VideoDetailView.h"
//#import "VisualModel.h"
@implementation VideoDetailView



- (instancetype)initWithFrame:(CGRect)frame VideoModel:(VisualModel *)videoModel
{
    self = [super initWithFrame:frame];
    if (self)
    {
        [self createSubviews:videoModel];
    }
    return self;
}

- (void)createSubviews:(VisualModel *)videoModel
{
    //图片
    self.pictureImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height / 2)];
    //self.pictureImageView.backgroundColor = [UIColor orangeColor];
    [self.pictureImageView sd_setImageWithURL:[NSURL URLWithString:videoModel.coverForDetail]];
    self.pictureImageView.userInteractionEnabled = YES;//用户交互
    [self addSubview:self.pictureImageView];
    
    //播放按钮
    self.playButton = [UIButton buttonWithType:UIButtonTypeCustom];
    self.playButton.frame = CGRectMake(self.pictureImageView.frame.size.width / 4 * 1.5, self.pictureImageView.frame.size.height / 3 , self.pictureImageView.frame.size.width / 8, self.pictureImageView.frame.size.width / 8);
    self.playButton.center = self.pictureImageView.center;//中心相等
    [self.playButton setBackgroundImage:[UIImage imageNamed:@"iconfont-bofang"] forState:UIControlStateNormal];
    [self.playButton addTarget:self action:@selector(buttonAction:) forControlEvents:UIControlEventTouchUpInside];
    [self.pictureImageView addSubview:self.playButton];
    
    //背景
    self.backgroundImageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, self.pictureImageView.frame.size.height, self.frame.size.width, self.frame.size.height / 2)];
    [self.backgroundImageView sd_setImageWithURL:[NSURL URLWithString:videoModel.coverBlurred]];
    [self addSubview:self.backgroundImageView];
    
    //标题
    self.titleLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 0, self.frame.size.width - 10, self.backgroundImageView.frame.size.height / 6)];
    //self.titleLabel.backgroundColor = [UIColor magentaColor];
    self.titleLabel.text = videoModel.title;
    self.titleLabel.textColor = [UIColor whiteColor];
    self.titleLabel.textAlignment = NSTextAlignmentLeft;
    self.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:19];
    [self.backgroundImageView addSubview:self.titleLabel];
    
    //白线
    UIView *view = [[UIView alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.size.height, self.titleLabel.frame.size.width / 2, 1)];
    view.backgroundColor = [UIColor whiteColor];
    [self.backgroundImageView addSubview:view];
    
    //类型
    self.categoryLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.titleLabel.frame.origin.x, self.titleLabel.frame.size.height + 1, self.frame.size.width / 5, self.titleLabel.frame.size.height)];
    //self.categoryLabel.backgroundColor = [UIColor blueColor];
    self.categoryLabel.text = [NSString stringWithFormat:@"#%@",videoModel.category];
    self.categoryLabel.textColor = [UIColor whiteColor];
    self.categoryLabel.textAlignment = NSTextAlignmentLeft;
    self.categoryLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
    [self.backgroundImageView addSubview:self.categoryLabel];
    
    //时长
    self.durationLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.categoryLabel.frame.origin.x + self.categoryLabel.frame.size.width, self.categoryLabel.frame.origin.y, self.categoryLabel.frame.size.width, self.categoryLabel.frame.size.height)];
    //self.durationLabel.backgroundColor = [UIColor cyanColor];
    NSString *string = [NSString stringWithFormat:@"%ld:",videoModel.duration / 60];
    NSString *string2 = [NSString stringWithFormat:@"%ld",videoModel.duration % 60];
    NSString *appendStr = [string stringByAppendingString:string2];
    self.durationLabel.text = [NSString stringWithFormat:@"/ %@",appendStr];
    self.durationLabel.textColor = [UIColor whiteColor];
    self.durationLabel.textAlignment = NSTextAlignmentLeft;
    self.durationLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
    [self.backgroundImageView addSubview:self.durationLabel];
    
    //描述
    self.descriptionLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.categoryLabel.frame.origin.x, self.categoryLabel.frame.origin.y + self.categoryLabel.frame.size.height, self.frame.size.width - self.categoryLabel.frame.origin.x, self.backgroundImageView.frame.size.height / 6 * 3)];
    //self.descriptionLabel.backgroundColor = [UIColor yellowColor];
    self.descriptionLabel.text = videoModel.descriptions;
    self.descriptionLabel.textColor = [UIColor whiteColor];
    self.descriptionLabel.textAlignment = NSTextAlignmentLeft;
    self.descriptionLabel.numberOfLines = 0;
    self.descriptionLabel.lineBreakMode = NSLineBreakByWordWrapping;
    //[self.descriptionLabel sizeToFit];
    self.descriptionLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
    [self.backgroundImageView addSubview:self.descriptionLabel];
    
    //收藏图标
    self.collectionCountImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.descriptionLabel.frame.origin.x, self.descriptionLabel.frame.origin.y + self.descriptionLabel.frame.size.height, self.backgroundImageView.frame.size.height / 6 / 2, self.backgroundImageView.frame.size.height / 6 / 2)];
    self.collectionCountImageView.image = [UIImage imageNamed:@"button0"];
    [self.backgroundImageView addSubview:self.collectionCountImageView];
    
    //收藏个数
    self.collectionCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.collectionCountImageView.frame.origin.x + self.collectionCountImageView.frame.size.width, self.collectionCountImageView.frame.origin.y, self.frame.size.width / 6, self.collectionCountImageView.frame.size.height)];
    //self.collectionCountLabel.backgroundColor = [UIColor greenColor];
    self.collectionCountLabel.text = [NSString stringWithFormat:@"%ld",(long)videoModel.collectionCount];
    self.collectionCountLabel.textColor = [UIColor whiteColor];
    self.collectionCountLabel.textAlignment = NSTextAlignmentCenter;
    self.collectionCountLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
    [self.backgroundImageView addSubview:self.collectionCountLabel];
    
    //分享图片
    self.shareCountImageView = [[UIImageView alloc] initWithFrame:CGRectMake(self.collectionCountLabel.frame.origin.x + self.collectionCountLabel.frame.size.width * 2, self.collectionCountLabel.frame.origin.y, self.backgroundImageView.frame.size.height / 6 / 2, self.backgroundImageView.frame.size.height / 6 / 2)];
    self.shareCountImageView.image = [UIImage imageNamed:@"iconfont-fenxiang"];
    [self.backgroundImageView addSubview:self.shareCountImageView];
    
    //分享个数
    self.shareCountLabel = [[UILabel alloc] initWithFrame:CGRectMake(self.shareCountImageView.frame.origin.x + self.shareCountImageView.frame.size.width, self.shareCountImageView.frame.origin.y, self.frame.size.width / 6, self.shareCountImageView.frame.size.height)];
    //self.shareCountLabel.backgroundColor = [UIColor purpleColor];
    self.shareCountLabel.text = [NSString stringWithFormat:@"%ld",(long)videoModel.shareCount];
    self.shareCountLabel.textColor = [UIColor whiteColor];
    self.shareCountLabel.textAlignment = NSTextAlignmentCenter;
    self.shareCountLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:15];
    [self.backgroundImageView addSubview:self.shareCountLabel];

}

- (void)buttonAction:(UIButton *)btn
{
    //执行协议
    [self.myDelegate pushToPlayerViewController];
}

@end
